package org.zfes.snowier.cloud.zbss.layer.tc.biz.service.impl;

import java.util.Map;
import java.util.Optional;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.idcenter.IDGenerator;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZBeanUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.zfes.snowier.common.dao.params.ParamMap;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.service.ICasereasonService;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.dao.CasereasonMapper;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.model.Casereason;

@Service
public class CasereasonServiceImpl implements ICasereasonService{
 	@Autowired
	private CasereasonMapper casereasonMapper;
	
	@Transactional(rollbackFor=Exception.class)
 	@Override
	public void createCasereason(Casereason casereason) {
		ZBeanUtil.validateBean(casereason);
		casereason.setId(IDGenerator.genLongId());
		casereasonMapper.insertSelective(casereason);
	}
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public Optional<Casereason> loadCasereasonById(Long id) {
		if(id!=null){
			return Optional.ofNullable(casereasonMapper.selectByPrimaryKey(id));
		}
		return Optional.empty();
		
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void updateCasereason(Casereason casereason) {
		ZBeanUtil.validateBean(casereason);
		casereasonMapper.updateByPrimaryKeySelective(casereason);
	}
	
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void deletCasereason(Long id) {
		if(id!=null){
			casereasonMapper.deleteByPrimaryKey(id);
			return;
		}
		ZAlert.Error("请选择要删除的数据");
		
	}
	
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public DataSet loadCasereasonDataSet(Map<String, Object> params) {
		ParamMap pm=ParamMap.filterParam(params);
		DataSet ds=DataSet.newDS(casereasonMapper.selectListCount(pm), casereasonMapper.selectList(pm));
		return ds;
	}
	
}